import axios from "axios";
import storage from '../utils/storage'
let { get } = storage
let BASEURL = 'http://lithii.top:2333/';
// let BASEURL = 'http://localhost:80/';
const service  = axios.create({
    baseURL:BASEURL,
    timeout:0
});
service.interceptors.request.use(
    conf=>{
        let baseData = {
            token:get('Blgo')?get('Blgo').token:null
        }
        conf.method === 'get'?
        conf.params = Object.assign(baseData,conf.params):
        conf.data = Object.assign(baseData,conf.data);
        // conf.headers['Content-Type'] = 'application/json;charset=utf-8';
        // conf.headers['Access-Control-Request-Headers'] = 'X-Requested-With';
        return conf;
    },err=>{
        Promise.reject(err)
    })

service.interceptors.response.use(
    res=>{
        return res.data
    },
    err=>{
        if(err){
            let text = '网络异常，请重试';
            alert(text);
        }
        return Promise.reject(err)
    }
)
export default service